﻿<!--#include file="../../lib/base.asp"-->
<!--#include file="../../theme/admin/config.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<%
''' 自定义系统参数插件
''' ==================================================================
''' 版权所有 http://www.ahseo.cc
''' ------------------------------------------------------------------
''' 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
''' 未经授权不允许对程序代码以任何形式任何目的的再发布。
''' ==================================================================
''' 插件编写: 寻云
''' 开发日期：2014.01

	'注释：插件是否安装
	is_plug_install "sdcms.plug.set"
	
	'注释：管理权限检查
	is_plug_login
	
	'注释：定义插件模板路径
	dim plug_theme,plug_theme_add,plug_theme_edit
	plug_theme="module/plug_set/list.html"
	plug_theme_add="module/plug_set/add.html"
	plug_theme_edit="module/plug_set/edit.html"
	
	'接收fget传值
	dim act:act=lcase(sdcms.fget("act",0))
	dim id:id=sdcms.getint(sdcms.fget("id",0),0)
	dim data
			
	select case act
		case "del":deldb
		case "add"
			load plug_theme_add
		case "adddb":adddb	
		case "edit"
			data=sdcms.db.dbload(1,"setName,setTitle,setType,setmode,fdatatype,flength,setValue,foptions,IsMust,frules,ordnum,isshow","sd_plug_set","id="&id&"","")
			load plug_theme_edit
		case "editdb":editdb
		case "order":ordernum	
		case "del":deldb
		case else
			load plug_theme
	end select	

	'保存新增字段
	sub adddb()
		dim t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13
		t0=sdcms.enhtml(sdcms.fpost("t0",0))
		t1=sdcms.enhtml(sdcms.fpost("t1",0))
		t2=sdcms.getint(sdcms.fpost("t2",0),0)
		t3=sdcms.getint(sdcms.fpost("t3",0),0)
		t4=sdcms.getint(sdcms.fpost("t4",0),0)
		t5=sdcms.getint(sdcms.fpost("t5",0),0)
		t6=sdcms.enhtml(sdcms.fpost("t6",0))
		t7=sdcms.enhtml(sdcms.fpost("t7",0))
		t8=sdcms.getint(sdcms.fpost("t8",0),0)
		t9=sdcms.getint(sdcms.fpost("t9",0),0)
		t11=sdcms.getint(sdcms.fpost("t11",0),0)
		t13=sdcms.getint(sdcms.fpost("t13",0),0)
		if sdcms.strlen(t0)=0 then sdcms.ajaxjson "参数名称不能为空",0:exit sub
		if sdcms.strlen(t1)=0 then sdcms.ajaxjson "参数标题不能为空",0:exit sub
		if sdcms.strlen(t2)=0 then sdcms.ajaxjson "参数类型不能为空",0:exit sub
		t0="my_"&t0
		if t8=0 then t9=0
		
		t0=left(t0,20)
		dim addtime
		addtime=now()
		dim data,ddata
		data=array(array("setName",t0,255,1),array("setTitle",t1,255,1),array("setType",t2,1,0),array("setmode",t3,1,0),array("fdatatype",t4,1,0),array("flength",t5,5,0),array("setValue",t6,255,1),array("foptions",t7,1,0),array("IsMust",t8,1,0),array("frules",t9,1,0),array("ordnum",t11,255,0),array("isshow",t13,1,0),array("AddTime",addtime,50,1))
		if sdcms.db.dbnew("sd_plug_set",data,"setName='"&t0&"'")=0 then
			sdcms.ajaxjson "字段名称已存在，请换个试试",0:exit sub
		else
		'保存字段到set表
		ddata=array(array("setname","sdcms.site",255,1),array("setkey",t0,255,1),array("setvalue",t6,255,1))
		
		sdcms.db.insert "sd_config",ddata
		
			sdcms.ajaxjson "保存成功",1
		end if

		
	end sub		
	
	'编辑
	sub editdb
		dim t1,t6,t7,t8,t9,t10,t11,t12,t13
		t1=sdcms.enhtml(sdcms.fpost("t1",0))
		t6=sdcms.enhtml(sdcms.fpost("t6",0))
		t7=sdcms.enhtml(sdcms.fpost("t7",0))
		t8=sdcms.getint(sdcms.fpost("t8",0),0)
		t9=sdcms.getint(sdcms.fpost("t9",0),0)
		t11=sdcms.getint(sdcms.fpost("t11",0),0)
		t13=sdcms.getint(sdcms.fpost("t13",0),0)
		if sdcms.strlen(t1)=0 then sdcms.ajaxjson "参数标题不能为空",0:exit sub
		if t8=0 then t9=0
		dim data,id,addtime,ddata
		addtime=now()
		id=sdcms.getint(sdcms.fget("id",0),0)
		data=array(array("setTitle",t1,255,1),array("setValue",t6,255,1),array("foptions",t7,1,1),array("IsMust",t8,1,0),array("frules",t9,1,0),array("ordnum",t11,255,0),array("isshow",t13,1,0),array("AddTime",addtime,50,1))
		if sdcms.db.dbupdate("sd_plug_set","id="&id&"",data)=1 then
		'ddata=db.dbload("1","setName,setTitle","sd_plug_set","id="&id&"","id")
		'sdcms.db.dbupdate "sd_config","setname='sdcms.site' and setkey='"&ddata(0,0)&"'",array(array("setvalue",t6,255,1))
			sdcms.ajaxjson "保存成功",1
		end if
	end sub
	
	'排序
	sub ordernum()
		dim t0,t1,t2,t3,i
		t0=sdcms.enhtml(sdcms.fpost("fid",0))
		t1=sdcms.enhtml(sdcms.fpost("ordernum",0))
		t2=split(t0,",")
		t3=split(t1,",")
		if ubound(t2)-ubound(t3)<>0 then sdcms.echo "0&#21442;&#25968;&#38169;&#35823;":exit sub
		for i=0 to ubound(t2)
			if sdcms.isnum(t2(i)) then
				sdcms.db.dbupdate "sd_plug_set","ID="&t2(i)&"",array(array("OrderNum",t3(i),10,0,0))
			end if
		next
		sdcms.echo "1"
	end sub
	
	'删除自定义字段
	sub deldb()
		dim fid:fid=sdcms.getint(sdcms.fget("fid",0),0)
		'查询字段ID、名称及所属模型ID
		dim fdata:fdata=sdcms.db.dbload(1,"id,setname","sd_plug_set","id="&fid&"","")
		
		'删除sd_config中的字段
		sdcms.db.dbdel "sd_config","setname='sdcms.site' and setkey='"&fdata(1,0)&"'"
			
		'删除sd_plug_filed中的字段
		sdcms.db.dbdel "sd_plug_set","id="&fid&""
				
		'打印处理结果		
		sdcms.echo "1&#21024;&#38500;&#25104;&#21151;"
	end sub
	
	'获取对应的字段类型
	function get_settype(byval t0)
		if not isnumeric(t0) then get_settype="参数不正确":exit function
		select case t0
			case "1":get_settype="单行文本框"
			case "2":get_settype="多行文本框"
			case "3":get_settype="下拉列表"
			case "4":get_settype="单选按钮"
			case "5":get_settype="复选框"
			case "6":get_settype="HTML编辑器"
		end select
	end function

	sdcms.db.dbclose
%>